library(forecast)
library(tseries)
library(fUnitRoots)
library(FitAR)
# R语言时间序列分析
revenue <- read.csv("F:/降水量.csv")
revenue
# 数据转换（ts）转换为时间序列的格式
revenue.ts <- ts(revenue[,2],frequency=12,start = c(2000,1))
revenue.ts 
start(revenue.ts)
end(revenue.ts)
is.ts(revenue.ts)
frequency(revenue.ts)
#绘制图形
plot.ts(revenue.ts,xlab='时间',ylab='降水量')
abline(lm(revenue.ts~time(revenue.ts)),col='red',lty=2,lwd=2)
# 偏自相关，自相关
acf(revenue.ts)
pacf(revenue.ts)
# 模型
fit <- auto.arima(revenue.ts)
fit
#模型检验
qqnorm(fit$residuals)
qqline(fit$residuals)
Box.test(fit$residuals,type="Ljung-Box")
#预测未来四年
fit.forecast <- forecast(fit,h=48)
fit.forecast
plot(fit.forecast)
